package com.learn.project2.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * @description: 前台静态资源文件访问
 * @author 岳子昂
 * @date 2022-01-11 14:36
 * @version 1.0
 */

@ComponentScan("com.learn.project2.service.wx.storage")
@EnableWebMvc
public class MvcConfiguration implements WebMvcConfigurer {
    @Value("${wxfile.url}")
    String url;

    @Value("${wxfile.maclocation}")
    String macLocation;

    @Value("${wxfile.winlocation}")
    String winLocation;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //静态资源映射mapping location
        String os = System.getProperty("os.name");

        // 判断操作系统
        if(os.toLowerCase().startsWith("mac")){
            registry.addResourceHandler(url).addResourceLocations("file:"+macLocation);
        }else if(os.toLowerCase().startsWith("win")){
          //  registry.addResourceHandler(url).addResourceLocations("file:"+winLocation);
            registry.addResourceHandler("/storage/upload/**").addResourceLocations("file:"+winLocation);
        }
    }

}
